﻿<UserControl x:Class="ScrumFactory.Team.ProjectTeam"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                                       
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             x:Name="thisView"
             
             mc:Ignorable="d" 
             
             
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding AddNewMemberCommand}"/>            
    </UserControl.InputBindings>
        
    
 

    <SF_Helpers:PanelLayout Title="{Binding PanelName}" >

        <!-- TOOLBAR -->
        <SF_Helpers:PanelLayout.Toolbar>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>

                <ToolBar Grid.Row="0">


                    <Menu>
                        <MenuItem                             
                                x:Name="addMemberMenuItem" Focusable="False"
                                Header="{x:Static props:Resources.Add_member}" IsEnabled="{Binding IsAddMemberVisible}"      
                                Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}"
                                Template="{StaticResource ToolBarMenu_TopLevelHeader}"
                                ItemsSource="{Binding Roles}">
                            
                            <MenuItem.ItemContainerStyle>
                                <Style TargetType="MenuItem">                                    
                                    <Setter Property="Focusable" Value="False"/>
                                    <Setter Property="Template" Value="{StaticResource ToolBarMenu_SubmenuItem}"/>
                                    <Setter Property="Command" Value="{Binding ElementName=thisView, Path=Model.SelectNewRoleCommand}"/>
                                    <Setter Property="CommandParameter" Value="{Binding Role}"/>
                                    <Style.Triggers>                                       
                                        <Trigger Property="MenuItem.IsPressed" Value="True">
                                            <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=addMemberComboBox}"/>
                                        </Trigger>                                       
                                    </Style.Triggers>
                                    
                                </Style>
                            </MenuItem.ItemContainerStyle>
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                            <MenuItem.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Focusable="False">
                                        <Image Source="/Images/ToolBar/TeamMember.png" Width="16" Height="16" Stretch="Uniform" Margin="0,0,5,0"/>
                                        <TextBlock Text="{Binding Role.RoleName}" VerticalAlignment="Center" />
                                    </StackPanel>
                                </DataTemplate>
                            </MenuItem.ItemTemplate>
                       
                        </MenuItem>
                  
                        <MenuItem  Header="{x:Static props:Resources.Join}" Command="{Binding ShowJoinDialogCommand}"
                              Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/joinProject.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>


                        <MenuItem Header="{x:Static props:Resources.Roles}" Command="{Binding ShowRolesListCommand}"
                              Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/editRoles.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>

                        <MenuItem Header="{x:Static props:Resources.Contacts}" Command="{Binding ShowContactListCommand}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/Contact_Book.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>


                    </Menu>

                </ToolBar>

                <Grid
                            
                            x:Name="newItemPanel" HorizontalAlignment="Left" Height="0"
                        Style="{StaticResource NewItemPanelAutoClose}"
                            Grid.Row="1">

                    <DockPanel VerticalAlignment="Top" HorizontalAlignment="Stretch">

                        <TextBlock 
                            x:Name="addMemberLabel" VerticalAlignment="Center" DockPanel.Dock="Left"
                            Style="{StaticResource LabelTextBlock}" Text="{Binding NewRole.RoleName, StringFormat={x:Static props:Resources.Add_member_as}}"/>

                        <SF_Helpers:FilteredComboBox            
                            x:Name="addMemberComboBox" IsEditable="True" Focusable="False"                            
                            BorderBrush="{StaticResource TextBoxBackgroundBrush}"
                            HorizontalAlignment="Left" VerticalAlignment="Center" Width="400" DockPanel.Dock="Left"
                            AlternationCount="2" MaxItemsResults="8"  MaxDropDownHeight="800"
                            SelectedValue="{Binding NewMember, UpdateSourceTrigger=PropertyChanged}" 
                            RefreshItemSource="{Binding RefreshMemberFilter}" CustomFilter="{Binding MemberCustomFilter}"
                            ItemTemplate="{StaticResource MemberDataTemplate}"
                            ItemsSource="{Binding Members}"
                           />

                        <TextBlock                         
                            Style="{StaticResource LabelTextBlock}" Text="{x:Static props:Resources.Member_work_load}" VerticalAlignment="Center" DockPanel.Dock="Left"/>


                        <ComboBox             
                            
                                VerticalAlignment="Center" Margin="3,0,0,0" DockPanel.Dock="Left"                           
                                SelectedValue="{Binding SearchMemberAvailability}"                                
                                Style="{StaticResource MemberAvailabilityComboBox}"/>

                    </DockPanel>



                </Grid>

            </Grid>

        </SF_Helpers:PanelLayout.Toolbar>

        <!-- CONTENT -->
        <SF_Helpers:PanelLayout.Content>
            <ListBox            
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            HorizontalAlignment="Stretch"
            Background="Transparent"            
            BorderThickness="0"            
            ItemContainerStyle="{StaticResource NoSelectionListBoxItem}"
            ItemsSource="{Binding GroupedProjectMemberships}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"  />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock
                                Margin="0,5,0,5"
                                Style="{StaticResource TitleTextBlock}"
                                Text="{Binding Path=Name, StringFormat='{}{0}(s)'}"/>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListBox.GroupStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,10,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>                                
                                <ColumnDefinition Width="230"/>                                
                            </Grid.ColumnDefinitions>

                            <ContentControl
                                Grid.Column="0"
                                Margin="5,0,10,0"
                                DataContext="{Binding Member}"
                                HorizontalAlignment="Center" VerticalAlignment="Top"
                                Style="{StaticResource MemberImageControlStyle}"/>

                            <StackPanel Grid.Column="1">
                                <StackPanel Orientation="Horizontal">

                                    <TextBlock
                                        Style="{StaticResource ItemTitleTextBlock}" VerticalAlignment="Center" MaxWidth="200" Margin="0,0,5,0"                              
                                        Text="{Binding Member.FullName}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

                                    <ComboBox                                                                         
                                        IsEnabled="{Binding UserCanChangeAllocation}"
                                        SF_Comp:CommandBehavior.RoutedEventName="SelectionChanged"  VerticalAlignment="Center" 
                                        SF_Comp:CommandBehavior.TheCommandToRun="{Binding ChangeDayAllocationCommand}"
                                        SelectedValue="{Binding ProjectMembership.DayAllocation}">
                                        <ComboBox.Style>
                                            <Style TargetType="ComboBox" BasedOn="{StaticResource MemberAllocationComboBox}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding UserCanChangeAllocation}" Value="False">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ComboBox.Style>
                                    </ComboBox>
                                    

                                </StackPanel>

                                <!--<TextBlock Text="{Binding Member.CompanyName}"  TextTrimming="CharacterEllipsis"/>-->
                                <TextBlock>                                
                                    <Hyperlink                                           
                                            SF_Comp:CommandBehavior.RoutedEventName="Click"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding SendEmailCommand}">
                                        <Run Text="{Binding Member.EmailAccount}" FontSize="{StaticResource SmallFontSize}" />    
                                    </Hyperlink>                                    
                                </TextBlock>
                                <TextBlock TextTrimming="CharacterEllipsis" FontSize="{StaticResource SmallFontSize}"
                                           Text="{Binding TotalHoursInThisProject, StringFormat={x:Static props:Resources.N_worked_hours}}"/>

                                <TextBlock Text="{x:Static props:Resources.not_engaged}"
                                           Background="{StaticResource AlertBackgroundBrush}" Foreground="{StaticResource AlertBrush}"
                                           FontSize="{StaticResource SmallFontSize}">
                                    <TextBlock.Style>
                                        <Style>
                                            <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                            <Style.Triggers>
                                                <MultiDataTrigger>
                                                    <MultiDataTrigger.Conditions>
                                                        <Condition Binding="{Binding ProjectMembership.DayAllocation}" Value="{x:Null}"/>                                                    
                                                        <Condition Binding="{Binding Member.IsContactMember}" Value="False"/>
                                                    </MultiDataTrigger.Conditions>
                                                    <Setter Property="TextBlock.Visibility" Value="Visible"/>
                                                </MultiDataTrigger>                                                                                                    
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                               


                            </StackPanel>

                            <DockPanel Grid.Column="1" Style="{StaticResource ItemActionMenu}">
                                <Button                                                     
                                    Style="{StaticResource RemoveActionButton}"
                                    Command="{Binding ElementName=thisView, Path=DataContext.RemoveMemberCommand}"
                                    CommandParameter="{Binding .}"/>
                            </DockPanel>

                            

                           
                        </Grid>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </SF_Helpers:PanelLayout.Content>

    </SF_Helpers:PanelLayout>

</UserControl>
